package com.authorization.project.authorization.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.authorization.project.authorization.mapper.MicroserviceRelationshipMapper;
import com.authorization.project.authorization.domain.MicroserviceRelationship;
import com.authorization.project.authorization.service.IMicroserviceRelationshipService;

/**
 * 微服务关系Service业务层处理
 * 
 * @author 李晓雷
 * @date 2020-04-24
 */
@Service
public class MicroserviceRelationshipServiceImpl implements IMicroserviceRelationshipService 
{
    @Autowired
    private MicroserviceRelationshipMapper microserviceRelationshipMapper;

    /**
     * 查询微服务关系
     * 
     * @param id 微服务关系ID
     * @return 微服务关系
     */
    @Override
    public MicroserviceRelationship selectMicroserviceRelationshipById(Long id)
    {
        return microserviceRelationshipMapper.selectMicroserviceRelationshipById(id);
    }

    /**
     * 查询微服务关系列表
     * 
     * @param microserviceRelationship 微服务关系
     * @return 微服务关系
     */
    @Override
    public List<MicroserviceRelationship> selectMicroserviceRelationshipList(MicroserviceRelationship microserviceRelationship)
    {
        return microserviceRelationshipMapper.selectMicroserviceRelationshipList(microserviceRelationship);
    }

    /**
     * 新增微服务关系
     * 
     * @param microserviceRelationship 微服务关系
     * @return 结果
     */
    @Override
    public int insertMicroserviceRelationship(MicroserviceRelationship microserviceRelationship)
    {
        return microserviceRelationshipMapper.insertMicroserviceRelationship(microserviceRelationship);
    }

    /**
     * 修改微服务关系
     * 
     * @param microserviceRelationship 微服务关系
     * @return 结果
     */
    @Override
    public int updateMicroserviceRelationship(MicroserviceRelationship microserviceRelationship)
    {
        return microserviceRelationshipMapper.updateMicroserviceRelationship(microserviceRelationship);
    }

    /**
     * 批量删除微服务关系
     * 
     * @param ids 需要删除的微服务关系ID
     * @return 结果
     */
    @Override
    public int deleteMicroserviceRelationshipByIds(Long[] ids)
    {
        return microserviceRelationshipMapper.deleteMicroserviceRelationshipByIds(ids);
    }

    /**
     * 删除微服务关系信息
     * 
     * @param id 微服务关系ID
     * @return 结果
     */
    @Override
    public int deleteMicroserviceRelationshipById(Long id)
    {
        return microserviceRelationshipMapper.deleteMicroserviceRelationshipById(id);
    }

    /**
     * 批量添加
     * @param microserviceId
     * @param relationIdsList
     */
    @Override
    public void bachInsertMicroserviceRelationship(Long microserviceId, List<Long> relationIdsList) {
        relationIdsList.stream().forEach(relationId ->{
            MicroserviceRelationship microserviceRelationship = new MicroserviceRelationship();
            microserviceRelationship.setRelationId(relationId);
            microserviceRelationship.setMicroserviceId(microserviceId);
            this.insertMicroserviceRelationship(microserviceRelationship);
        });

    }

    /**
     * 根据微服务主键删除
     * @param microserviceId
     */
    @Override
    public void deleteMicroserviceRelationshipByMicroserviceId(Long microserviceId) {
        microserviceRelationshipMapper.deleteMicroserviceRelationshipByMicroserviceId(microserviceId);
    }

    @Override
    public List<Long> selectRelationIdsByMicroserviceId(Long microserviceId) {
        return microserviceRelationshipMapper.selectRelationIdsByMicroserviceId(microserviceId);
    }
}
